const { request } = require("../utils/request.js")
const { login,baseUrl,banner,goods,hotSearch,search,goodsDetails,cart,addCart,delCart,category,buy,smsSend,smsVerify, authBaseUrl} = require("./base")
/**
 * 网络请求方法
 */
function getHotProducts() {
  return request(baseUrl + `/product/findAll`, "POST", {})
}
/**
 * get banner data
 */
function getCarouselByPosition(position) {
  // 拼接接口地址：baseUrl + /carousel/find/{position}
  return request(baseUrl + `/carousel/find/${position}`, "GET");
}

/**
 * 商品套餐展示
 */

function getHotPackages() {
  return request(baseUrl + `/package/findTopSales`, "GET");
}
/**
 * 查询套餐内容
 * @param {} productName 
 */
function getPackagedetails(id){
  return request(baseUrl+`/package/find/${id}`,"GET",{})
}
/**
 * hot search keywords
 */
function getHotSearch(productName){
    return request(baseUrl + `/product/find?productName=${productName}`,"POST",{})
}

/**
 * search 
 */
function getSearch(data){
    return request(baseUrl + search,"GET",data)
}

/**
 * goods details
 */
function getGoodsDetails(data){
    return request(baseUrl + goodsDetails,"GET",data) 
}

/**
 * cart select
 */
function getCart(data){
    return request(baseUrl + cart,"GET",data) 
}

/**
 * cart add
 */
function addGoodsCart(data){
    return request(baseUrl + addCart,"GET",data) 
}

/**
 * cart del
 */
function delGoodsCart(data){
    return request(baseUrl + delCart,"GET",data) 
}

/**
 * 获取商品分类
 */
function getProductType(){
    return request(baseUrl + `/productType/list`,"POST") 
}

/**
 * 根据id获取
 * @param {*} data 
 */
function getProductTypeId(typeId){
    return request(baseUrl+`/product/findProductByTypeId/${typeId}`,"POST",{})
}

// api/index.js 新增方法
function getProductDetail(productId) {
  return request(baseUrl + `/product/findProductById/${productId}`, "POST", {});
}
/**
 * buy
 */
function getBuy(data){
    return request(baseUrl + buy,"GET",data) 
}
/**
 * 
 * @param {登录} data 
 */
function getLogin(data){
    return request(authBaseUrl + `/user/login`,"POST",data) 
}

/**
 * 发送短信验证码给手机号
 */
function getSmsCode(phone){
  return request(authBaseUrl+`/sms/sendSms/${phone}`,"GET")
}

function verifySmsCode(data){
  return request(authBaseUrl+smsVerify,"POST",data)
}


module.exports = {
    getHotProducts,  // 新增导出
    getProductDetail,
    getCarouselByPosition,
    getHotPackages,
    getPackagedetails,
    getHotSearch,
    getSearch,
    getGoodsDetails,
    getCart,
    addGoodsCart,
    delGoodsCart,
    getProductType,
    getProductTypeId,
    getBuy,
    getLogin,
    getSmsCode,
    verifySmsCode
}